package com.yuxl.admin.manager.auth.core.repository;

import com.yuxl.admin.manager.auth.core.entity.AuthRolePower;
import org.springframework.data.r2dbc.repository.Query;
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
import reactor.core.publisher.Flux;

import java.util.Set;

/**
 * @Author : yuxl
 * @create 2024/10/29 10:12
 */
public interface AuthRolePowerRepository extends ReactiveCrudRepository<AuthRolePower, Long> {

    @Query("""
        SELECT * FROM auth_role_power WHERE type = '接口' and  power_id = :interfaceId
        """)
    Flux<AuthRolePower> findByInterfaceId(Long interfaceId);

    @Query("""
        SELECT * FROM auth_role_power WHERE type = '接口' and  role_id in (:roleIds)
        """)
    Flux<AuthRolePower> findInterfaceIdByRoleIdIn(Set<Long> roleIds);

    @Query("""
        SELECT * FROM auth_role_power WHERE type = '菜单' and  power_id = :menuId
        """)
    Flux<AuthRolePower> findByMenuId(Long menuId);

    @Query("""
        SELECT * FROM auth_role_power WHERE type = '菜单' and  role_id in (:roleIds)
        """)
    Flux<AuthRolePower> findMenuIdByRoleIdIn(Set<Long> roleIds);

    @Query("""
        SELECT * FROM auth_role_power WHERE type = '操作' and  power_id = :operateId
        """)
    Flux<AuthRolePower> findByOperateId(Long operateId);

    @Query("""
        SELECT * FROM auth_role_power WHERE type = '操作' and  role_id in (:roleIds)
        """)
    Flux<AuthRolePower> findOperateIdByRoleIdIn(Set<Long> roleIds);

    Flux<AuthRolePower> findByRoleId(Long roleId);

    Flux<AuthRolePower> findByRoleIdIn(Set<Long> roleIds);
}
